
var ModelCollection = function(layout){
	this.models = new Array();
	this.layout = layout;
	this['edges'] = {};
	
	this.defaultEdgeProperties = {
			'pixelColor': '#c4c4c4',
			'pixelWidth': '2px',
			'pixelHeight': '2px',
			'pixels': 10
		}
}

ModelCollection.prototype.addEdge = function( particleA, particleB, edgeProperties ) {

	if ( !this['edges'][particleA.id] ) {
		this['edges'][particleA.id]={};
	}

	if ( !this['edges'][particleA.id][particleB.id] ) {		
		// create the "pixels" used to draw the edge
		var edgePixels = new Array();

		if ( !edgeProperties ) {
			edgeProperties = this.defaultEdgeProperties;
		}
	
		var pixelCount = edgeProperties.pixels;
		var pixels = [];

		for ( var k=0, l=pixelCount; k<l; k++ ) {
			var pixel = document.createElement('div');
			pixel.style.width = edgeProperties.pixelWidth;
			pixel.style.height = edgeProperties.pixelHeight;
			pixel.style.backgroundColor = edgeProperties.pixelColor;
			pixel.style.position = 'absolute';
			pixel.innerHTML="<img height=1 width=1/>";
			edgePixels.push( pixel );
			//this.container.appendChild(pixel);
		}

		this['edges'][particleA.id][particleB.id] = {
			source: particleA,
			target: particleB,
			edge: edgePixels
		}
				
		return edgePixels;
	} else {
		return this['edges'][particleA.id][particleB.id].edge;
	}
}

ModelCollection.prototype.addModel = function(model) {
	this.models.push(model);
}

ModelCollection.prototype.remove = function(key) {
	
	var sexArray = new Array();
	var lForArray = new Array();
	var rStatusArray = new Array();
	var intInArray = new Array();
		
	if(key.substring(0,1) == "1")
		sexArray.push("male");
	if(key.substring(1,2) == "1")
		sexArray.push("female");
	if(key.substring(2,3) == "1")
		sexArray.push("");
	if(key.substring(3,4) == "1")
		lForArray.push("friendship");
	if(key.substring(4,5) == "1")
		lForArray.push("dating");
	if(key.substring(5,6) == "1")
		lForArray.push("a relationship");
	if(key.substring(6,7) == "1")
		lForArray.push("networking");
	if(key.substring(7,8) == "1")
		lForArray.push("");	
	if(key.substring(8,9) == "1")
		rStatusArray.push("single");
	if(key.substring(9,10) == "1")
		rStatusArray.push("In a Relationship");
	if(key.substring(10,11) == "1")
		rStatusArray.push("engaged");
	if(key.substring(11,12) == "1")
		rStatusArray.push("married");
	if(key.substring(12,13) == "1")
		rStatusArray.push("it's complicated");
	if(key.substring(13,14) == "1")
		rStatusArray.push("In an Open Relationship");
	if(key.substring(14,15) == "1")
		rStatusArray.push("");	
	if(key.substring(15,16) == "1")
		intInArray.push("male");
	if(key.substring(16,17) == "1")
		intInArray.push("female");
	if(key.substring(17,18) == "1")
		intInArray.push("");	
	
	for(var i = 0; i < this.models.length; i++){
		if(this.checkControl(this.models[i].sex, sexArray) && this.checkControl(this.models[i].lookingFor, lForArray) &&
				this.checkControl(this.models[i].rStatus, rStatusArray) && this.checkControl(this.models[i].intIn, intInArray)){
			if(this.models[i].onGraph == 0){			
				
				var node = new DataGraphNode();
				node.color= "#000000";
				node.smiley= "user";
				node.mass=0.5;			
				
				var domElement = this.layout.makeNodeView( node, this.layout.model.particles[this.models[i].id] );
				this.layout.view.addNode( this.layout.model.particles[this.models[i].id], domElement );	
				this.models[i].onGraph = 1;
			}			
		}
		else{	
			if(this.models[i].onGraph == 1){
				this.layout.view.removeNode(this.layout.model.particles[this.models[i].id]);
				this.models[i].onGraph = 0;
			}
		}	
	}	
}

ModelCollection.prototype.checkControl = function(key, anArray) {
	
	for(var i = 0; i < anArray.length; i++){
		for(var j = 0; j < key.length; j++)
			if(key[j] == anArray[i])
				return true;
	}		
	return false;	
}

var Model = function(id, sex, rStatus){
	this.id = id;
	this.sex = new Array();
	this.sex.push(sex);
	this.lookingFor = new Array();
	this.rStatus = new Array();
	this.rStatus.push(rStatus);
	this.intIn = new Array();
	this.onGraph = 1;
}
Model.prototype.addLookingFor = function(key) {
	this.lookingFor.push(key);
}
Model.prototype.addIntIn = function(key) {
	this.intIn.push(key);
}